/*
day152_2
2020.1.27
*/
#include<iostream>
#include<unordered_set>
#include<vector>
#include<cmath> 
using namespace std;

class Solution {
public:
    vector<int> powerfulIntegers(int x, int y, int bound) 
	{
		vector<int> res;
		unordered_set<int> set;
		int a,b;
		a=log(x)==0 ? 0:log(bound)/log(x);
		b=log(y)==0 ? 0:log(bound)/log(y);
//		cout<<b<<endl; 
        for(int i=0;i<=a;i++)
        {
        	for(int j=0;j<=b;j++)
        	{
        		int tem=pow(x,i)+pow(y,j);
//        		cout<<tem<<endl;
        		if(tem<=bound) set.insert(tem);
        		else break;
			}
		}
		
		for(auto &s :set)
		{
			res.push_back(s);
		}
		
		return res;
    }
};


int main()
{
	Solution s;
	
	int x=2,y=1,bound=10;
	vector<int> res=s.powerfulIntegers(x,y,bound);
	for(auto &a : res)
	{
		cout<<a<<'\t';
	}
	cout<<endl;
	return 0;
}
